home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 22 / AACD 22.iso / AACD / System / ps2m / wbm.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-04-07  |  5.5 KB  |  245 lines

  1. /*  This software is distributed under GPL license - see gpl.txt
  2.     This is a part of WheelBusMouse and ps2m packages,
  3.     you can obtain latest versions at Aminet:
  4.  
  5. ftp://ftp.wustl.edu/pub/aminet/util/mouse/WheelBusMouse.lha
  6. ftp://ftp.wustl.edu/pub/aminet/util/mouse/WheelBusMouse.readme
  7.  
  8. ftp://ftp.wustl.edu/pub/aminet/hard/hack/ps2m.lha
  9. ftp://ftp.wustl.edu/pub/aminet/hard/hack/ps2m.readme
  10.  
  11. For any questions: rdc@mindless.com
  12.  
  13. Don't forget to disable startup code! */
  14.  
  15. #include <exec/memory.h>
  16. #include <clib/dos_protos.h>
  17. #include <clib/exec_protos.h>
  18. #include <clib/input_protos.h>
  19. #include <clib/graphics_protos.h>
  20. #include <pragmas/exec_sysbase_pragmas.h>
  21. #include <pragmas/graphics_pragmas.h>
  22. #include <pragmas/input_pragmas.h>
  23. #include <pragmas/dos_pragmas.h>
  24. #include <dos/dostags.h>
  25.  
  26. #include <devices/input.h>
  27. #include <devices/inputevent.h>
  28. #include "newmouse.h"
  29.  
  30. struct Library *DOSBase, *SysBase, *GfxBase, *InputBase;
  31. struct IOStdReq *req;
  32. struct InputEvent FakeEvent;
  33.  
  34. ULONG code;
  35.  
  36. #define COORDX *((STRPTR)0xdff00d)
  37. #define COORDY *((STRPTR)0xdff00c)
  38. #define POTGOR *((STRPTR)0xdff016)
  39. #define PRA *((STRPTR)0xbfe001)
  40. #define TEMPLATE "REVERSE/S,REVERSEX=RX/S,REVERSEY=RY/S,LMB/S,MMB/S,RMB/S,JOYFIRE0=JF0/S,JOYFIRE1=JF1/S,JOYFIRE2=JF2/S,CTRL/S,LSHIFT=LSH/S,RSHIFT=RSH/S,LALT/S,RALT/S,LCOMMAND=LCMD/S,RCOMMAND=RCMD/S,PRIORITY/N,QUIET/S"
  41.  
  42. struct {
  43.     ULONG reverse;
  44.     ULONG rx;
  45.     ULONG ry;
  46.     ULONG lmb;
  47.     ULONG mmb;
  48.     ULONG rmb;
  49.     ULONG jf0;
  50.     ULONG jf1;
  51.     ULONG jf2;
  52.     ULONG ctrl;
  53.     ULONG lsh;
  54.     ULONG rsh;
  55.     ULONG lalt;
  56.     ULONG ralt;
  57.     ULONG lcmd;
  58.     ULONG rcmd;
  59.     ULONG *pri;
  60.     ULONG quiet;
  61. } arg = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  62.  
  63. void event(LONG);
  64. void eventc(LONG);
  65. void process(void);
  66.  
  67. __saveds main()
  68. {
  69.     SysBase = *((struct Library **)4L);
  70.     if(DOSBase = OpenLibrary("dos.library",0))
  71.     {
  72.         if(GfxBase = OpenLibrary("graphics.library",36))
  73.         {
  74.             struct RDArgs *rda;
  75.             if(rda = ReadArgs(TEMPLATE,(LONG *)&arg,NULL))
  76.             {
  77.                 if(!arg.quiet)
  78.                 {
  79.                     Printf("%s  © Russian Digital Computing\n",6+"$VER: WheelBusMouse 1.2 "__AMIGADATE__);
  80.                 }
  81.                 if(FindTask("WheelBusMouse"))
  82.                 {
  83.                     Printf("%s already installed!\n","WheelBusMouse");
  84.                 }
  85.                 else
  86.                 {
  87.                     if(CreateNewProcTags(NP_Entry,process,NP_Name,"WheelBusMouse",NP_Priority,arg.pri?*arg.pri:0,NULL))
  88.                     {
  89.                         ((struct CommandLineInterface *)((((struct Process *)FindTask(NULL))->pr_CLI)<<2))->cli_Module = NULL;
  90.                         return(0);
  91.                     }
  92.                     if(!arg.quiet)
  93.                     {
  94.                         Printf("Can't create daughter process\n");
  95.                     }
  96.                 }
  97.                 CloseLibrary(GfxBase);
  98.             }
  99.         }
  100.         else
  101.         {
  102.             Write(Output(),"OS 2.0+ required\n",17);
  103.         }
  104.         CloseLibrary(DOSBase);
  105.     }
  106.     return(20);
  107. }
  108.  
  109. void __saveds process(void)
  110. {
  111.     struct MsgPort *replyport;
  112.     if(replyport = CreateMsgPort())
  113.     {
  114.         if(req = CreateIORequest(replyport,sizeof(struct IOStdReq)))
  115.         {
  116.             if(!OpenDevice("input.device",NULL,(struct IORequest *)req,NULL))
  117.             {
  118.                 BYTE LastByteX = COORDX;
  119.                 BYTE LastByteY = COORDY;
  120.                 ULONG qualc = arg.ctrl | arg.lalt | arg.ralt | arg.lsh | arg.rsh | arg.lcmd | arg.rcmd;
  121.                 ULONG qualp = arg.mmb | arg.rmb | arg.jf2 | arg.jf1;
  122.                 ULONG quala = arg.lmb | arg.jf0;
  123.                 ULONG qual = quala | qualp | qualc;
  124.                 InputBase = (struct Library *)req->io_Device;
  125.                 while(!CheckSignal(0xf000))
  126.                 {
  127.                     BYTE CurrByteX = COORDX;
  128.                     BYTE CurrByteY = COORDY;
  129.                     LONG diffx = (BYTE)(CurrByteX - LastByteX);
  130.                     LONG diffy = (BYTE)(CurrByteY - LastByteY);
  131.                     if(diffx || diffy)
  132.                     {
  133.                         if(arg.reverse)
  134.                         {
  135.                             diffx = -diffx;
  136.                             diffy = -diffy;
  137.                         }
  138.                         if(qual)
  139.                         {
  140.                             ULONG qua = 0;
  141.                             if(qualc)
  142.                             {
  143.                                 UWORD t = PeekQualifier();
  144.                                 if((arg.ctrl&&(t&IEQUALIFIER_CONTROL))||
  145.                                     (arg.lsh&&(t&IEQUALIFIER_LSHIFT))||
  146.                                     (arg.rsh&&(t&IEQUALIFIER_RSHIFT))||
  147.                                     (arg.lcmd&&(t&IEQUALIFIER_LCOMMAND))||
  148.                                     (arg.rcmd&&(t&IEQUALIFIER_RCOMMAND))||
  149.                                     (arg.lalt&&(t&IEQUALIFIER_LALT))||
  150.                                     (arg.ralt&&(t&IEQUALIFIER_RALT)))
  151.                                 {
  152.                                     qua = 1;
  153.                                 }
  154.                             }
  155.                             if(quala)
  156.                             {
  157.                                 BYTE t = PRA;
  158.                                 if((arg.lmb&&(!(t&64)))||
  159.                                     (arg.jf0&&(!(t&128))))
  160.                                 {
  161.                                     qua = 1;
  162.                                 }
  163.                             }
  164.                             if(qualp)
  165.                             {
  166.                                 BYTE t = POTGOR;
  167.                                 if((arg.mmb&&(!(t&1)))||
  168.                                     (arg.rmb&&(!(t&4)))||
  169.                                     (arg.jf2&&(!(t&16)))||
  170.                                     (arg.jf1&&(!(t&64))))
  171.                                 {
  172.                                     qua = 1;
  173.                                 }
  174.                             }
  175.                             if(qua)
  176.                             {
  177.                                 LONG temp = diffx;
  178.                                 diffx = diffy;
  179.                                 diffy = temp;
  180.                             }
  181.                         }
  182.                         if(diffx)
  183.                         {
  184.                             code = NM_WHEEL_LEFT;
  185.                             if(arg.rx)
  186.                             {
  187.                                 diffx = -diffx;
  188.                             }
  189.                             if(diffx<0)
  190.                             {
  191.                                 code++;
  192.                                 diffx = -diffx;
  193.                             }
  194.                             eventc(diffx);
  195.                         }
  196.                         if(diffy)
  197.                         {
  198.                             code = NM_WHEEL_UP;
  199.                             if(arg.ry)
  200.                             {
  201.                                 diffy = -diffy;
  202.                             }
  203.                             if(diffy<0)
  204.                             {
  205.                                 code++;
  206.                                 diffy = -diffy;
  207.                             }
  208.                             eventc(diffy);
  209.                         }
  210.                         LastByteX=CurrByteX;
  211.                         LastByteY=CurrByteY;
  212.                     }
  213.                     WaitTOF();
  214.                 }
  215.                 CloseDevice((struct IORequest *)req);
  216.             }
  217.             DeleteIORequest(req);
  218.         }
  219.         DeleteMsgPort(replyport);
  220.     }
  221.     CloseLibrary(GfxBase);
  222.     CloseLibrary(DOSBase);
  223. }
  224.  
  225. void eventc(LONG count)
  226. {
  227.     while(count--)
  228.     {
  229.         event(IECLASS_RAWKEY);
  230.         event(IECLASS_NEWMOUSE);
  231.     }
  232. }
  233.  
  234. void event(LONG class)
  235. {
  236.     FakeEvent.ie_NextEvent = NULL;
  237.     FakeEvent.ie_Class = class;
  238.     FakeEvent.ie_Code = code;
  239.     FakeEvent.ie_Qualifier = NULL;
  240.     req->io_Data = (APTR)&FakeEvent;
  241.     req->io_Length = sizeof(struct InputEvent);
  242.     req->io_Command = IND_WRITEEVENT;
  243.     DoIO((struct IORequest *)req);
  244. }
  245.